package com.econ.powercloud.ems.common.enums;

import java.util.Arrays;
import java.util.List;

public enum IotMsgStatus implements EnumMethod {

    /**  */
    SENT(1,"平台/系统发送"),
    DEVICE_REQUEST(2, "设备请求"),
    FIRST_REPLY(3,"设备第一次响应"),
    SECOND_SENT(4,"平台第二次发送"),
    FINISHED(9,"已完成"),
    FIRST_ACK_FAIL(97,"设备第一次响应失败"),
    SECOND_ACK_FAIL(98,"设备第二次响应失败"),
    TIMEOUT(99, "发送等待响应超时"),
    ;

    private Integer code;
    private String desc;

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    IotMsgStatus(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static IotMsgStatus fromCode(int code){
        for(IotMsgStatus deviceType: IotMsgStatus.values()){
            if(deviceType.getCode() == code){
                return deviceType;
            }
        }
        return SENT;
    }

    public static List<IotMsgStatus> getRunningStatus() {
        return Arrays.asList(SENT, SECOND_SENT);
    }

    /**
     * 获取所有最终状态
     */
    public static List<IotMsgStatus> getFinalStatus() {
        return Arrays.asList(FINISHED, FIRST_ACK_FAIL,SECOND_ACK_FAIL,TIMEOUT);
    }
}
